#!/usr/bin/python3
# -*- coding: utf-8 -*-
# @Author: Sricor
# @Date: 2022-10-25

""" Task Class
      校本化
"""
from aiohttp import ClientSession

from yiban.Core import SchoolBased, BaseReq
from yiban.Core import TaskFeedback
from yiban.Core import SchoolBasedAuth
from yiban.Core import EpidemicPrevention


class Task:
    def __init__(self, mobile: str, password: str):
        self.task_feedback: TaskFeedback|None = None
        self.epidemic_prevention: EpidemicPrevention|None = None
        self.req: BaseReq|None = None
        self._mobile = mobile
        self._password = password

    async def init_task(self, access_token: str, req: BaseReq = None):
        if req is None:
            self.req = await SchoolBasedAuth(mobile=self._mobile, password=self._password, access_token=access_token)._auth()
        else:
            self.req = req

        self.task_feedback = TaskFeedback(self.req)  # 任务反馈
        self.epidemic_prevention = EpidemicPrevention(self.req)  # 疫情防控

    async def get_task_feedback_completed_task(self):
        return await self.task_feedback.get_completed_task()

    async def get_task_feedback_uncompleted_task(self):
        return await self.task_feedback.get_uncompleted_task()

    async def submit_task_feedback(self, data):
        return await self.task_feedback.submit_task(data)

    async def get_epidemic_prevention_uncompleted_task(self):
        return await self.epidemic_prevention.get_uncompleted_task()

    async def get_epidemic_prevention_completed_task(self):
        return await self.epidemic_prevention.get_completed_task()

    async def submit_epidemic_prevention(self, title, data):
        return await self.epidemic_prevention.submit_task(title, data)

    async def submit_sign_feedback(self, data):
        return await self.task_feedback.submit_sign(data)

    async def close_task_req(self):
        await self.req.close()

    @staticmethod
    def task_aes_encrypt(data):
        return SchoolBased.aes_encrypt(data)

    @staticmethod
    def task_aes_decrypt(data):
        return SchoolBased.aes_decrypt(data)
